package mySwingToolkit.ui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;


import mySwingToolkit.model.ClassModel;

public class RowRenderer<T> extends DefaultTableCellRenderer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	//渲染器  用来改变颜色
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		
		@SuppressWarnings("unchecked")
		ClassModel<T> obj=(ClassModel<T>) table.getValueAt(row, 0);
		Component c=super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		if(obj!=null){
			switch(obj.getStatus()){
			case ClassModel.INSERT:
				this.setBackground(new Color(0,255,0));
				break;
			case ClassModel.DELETE:
				this.setBackground(new Color(255,0,0));
				break;
			case ClassModel.UPDATE:
				this.setBackground(new Color(200,200,200));
				break;
			case ClassModel.NORMAL:
				this.setBackground(new Color(255,255,255));
				break;
			default :
				break;
			}
		}else{
			this.setBackground(new Color(255,255,255));
		}
		return c;
	}

}
